/*
 * @Author: Zeratul
 * @Date: 2020-08-19 19:02:36
 * @LastEditTime: 2020-08-19 19:46:51
 * @FilePath: \eleme-user\src\Routes\PrivateRoute.js
 */
import React, { Component } from "react";
import { Route, Redirect } from "react-router-dom";
import { connect } from "react-redux";

/**
 * 路由守卫
 */
class PrivateRoute extends Component {
  render() {
    const { isLogin, path, component, location } = this.props;
    if (isLogin) {
      return <Route path={path} componen={component}></Route>;
    } else {
      return (
        <Redirect
          to={{ pathname: "./login", state: location.pathname }}
        ></Redirect>
      );
    }
  }
}

const mapStateToProps = (state) => {
  return {};
};

const mapDispatchToProps = (dispatch) => {
  return {};
};
export default connect(mapStateToProps, mapDispatchToProps)(PrivateRoute);
